﻿using System;
using System.Text;
using System.Net;
using System.IO;

namespace NeroConnect.Network
{
	/// <summary>Represents a response to a request being handled by an IListener object.</summary>
	public interface IListenerResponse : IDisposable
	{
		/// <summary>Gets or sets the System.Text.Encoding for this response's OutputStream.</summary>
		/// <value>An System.Text.Encoding object suitable for use with the data in the OutputStream property, or null if no encoding is specified.</value>
		Encoding ContentEncoding { get; set; }
		/// <summary>Gets or sets the number of bytes in the body data included in the response.</summary>
		/// <value>The value of the response's Content-Length header.</value>
		/// <exception cref="System.ArgumentOutOfRangeException">The value specified for a set operation is less than zero.</exception>
		/// <exception cref="System.InvalidOperationException">The response is already being sent.</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		long ContentLength64 { get; set; }
		/// <summary>Gets or sets the MIME type of the content returned.</summary>
		/// <value>A System.String instance that contains the text of the response's Content-Type header.</value>
		/// <exception cref="System.ArgumentNullException">The value specified for a set operation is null.</exception>
		/// <exception cref="System.ArgumentException">The value specified for a set operation is an empty string ("").</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		string ContentType { get; set; }
		/// <summary>Gets or sets the collection of header name/value pairs returned by the server.</summary>
		/// <value>A System.Net.WebHeaderCollection instance that contains all the explicitly set HTTP headers to be included in the response.</value>
		/// <exception cref="System.InvalidOperationException">The System.Net.WebHeaderCollection instance specified for a set operation is not valid for a response.</exception>
		WebHeaderCollection Headers { get; }
		/// <summary>Gets or sets a value indicating whether the server requests a persistent connection.</summary>
		/// <value>true if the server requests a persistent connection; otherwise, false. The default is true.</value>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		bool KeepAlive { get; set; }
		/// <summary>Gets a System.IO.Stream object to which a response can be written.</summary>
		/// <value>A System.IO.Stream object to which a response can be written.</value>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		Stream OutputStream { get; }
		/// <summary>Gets or sets whether the response uses chunked transfer encoding.</summary>
		/// <value>true if the response is set to use chunked transfer encoding; otherwise, false. The default is false.</value>
		bool SendChunked { get; set; }
		/// <summary>Gets or sets the HTTP status code to be returned to the client.</summary>
		/// <value>A System.Net.HttpStatusCode value that specifies the HTTP status code for the requested resource. The default is System.Net.HttpStatusCode.OK, indicating that the server successfully processed the client's request and included the requested resource in the response body.</value>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		/// <exception cref="System.Net.ProtocolViolationException">The value specified for a set operation is not valid. Valid values are between 100 and 999 inclusive.</exception>
		System.Net.HttpStatusCode StatusCode { get; set; }
		/// <summary>Gets or sets a text description of the HTTP status code returned to the client.</summary>
		/// <value>The text description of the HTTP status code returned to the client. The default is the RFC 2616 description for the StatusCode property value, or an empty string ("") if an RFC 2616 description does not exist.</value>
		string StatusDescription { get; }
		/// <summary>Closes the connection to the client without sending a response.</summary>
		void Abort();
		/// <summary>Adds the specified header and value to the HTTP headers for this response.</summary>
		/// <param name="name">The name of the HTTP header to set.</param>
		/// <param name="value">The value for the name header.</param>
		/// <exception cref="System.ArgumentNullException">name is null or an empty string ("").</exception>
		/// <exception cref="System.ArgumentException">You are not allowed to specify a value for the specified header.-or-name or value contains invalid characters.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">The length of value is greater than 65,535 characters.</exception>
		void AddHeader(string name, string value);
		/// <summary>Appends a value to the specified HTTP header to be sent with this response.</summary>
		/// <param name="name">The name of the HTTP header to append value to.</param>
		/// <param name="value">The value to append to the name header.</param>
		/// <exception cref="System.ArgumentException">name is null or an empty string ("").-or-You are not allowed to specify a value for the specified header.-or-name or value contains invalid characters.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">The length of value is greater than 65,535 characters.</exception>
		void AppendHeader(string name, string value);
		/// <summary>Sends the response to the client and releases the resources held by this IListenerResponse instance.</summary>
		void Close();
		/// <summary>Configures the response to redirect the client to the specified URL.</summary>
		/// <param name="url">The URL that the client should use to locate the requested resource.</param>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
		void Redirect(string url);
	}
}
